package br.com.lh.urabuilder.model
{
	import br.com.lh.urabuilder.business.ArrowManager;
	import br.com.lh.urabuilder.business.ArrowManagerImpl;
	import br.com.lh.urabuilder.business.ISelectableComponentsManager;
	import br.com.lh.urabuilder.business.RectangleSelection;
	import br.com.lh.urabuilder.business.ResourceManagerImpl;
	import br.com.lh.urabuilder.business.ViewManager;
	import br.com.lh.urabuilder.business.ViewManagerImpl;
	import br.com.lh.urabuilder.business.XmlManager;
	import br.com.lh.urabuilder.business.XmlManagerImpl;
	import br.com.lh.urabuilder.business.ZoomManager;
	import br.com.lh.urabuilder.control.EventHelper;
	import br.com.lh.urabuilder.domain.session.SessionHolder;
	import br.com.lh.urabuilder.helper.ArrowDragHelper;
	import br.com.lh.urabuilder.helper.DragAndDropHelper;
	import br.com.lh.urabuilder.helper.KeyBoardHelper;
	import br.com.lh.urabuilder.helper.LinkHelper;
	import br.com.lh.urabuilder.helper.MouseEventHelper;
	import br.com.lh.urabuilder.helper.PropertieHelper;
	import br.com.lh.urabuilder.helper.ScrollHelper;
	import br.com.lh.urabuilder.helper.dragdrop.DragDropDelegator;
	import br.com.lh.urabuilder.helper.dragdrop.IDragAndDropDelegator;
	import br.com.lh.urabuilder.util.SelectableComponentsUtils;
	import br.com.lh.urabuilder.view.properties.IUraPropertiesPanel;
	
	import com.adobe.cairngorm.model.ModelLocator;
	
	import mx.containers.Canvas;
	import mx.core.UIComponent;
	
	[Bindable]
	public class UraModelLocator implements ModelLocator
	{
	public static var modelLocator : UraModelLocator;
      
      public var xmlManager:XmlManager;
      public var viewManager:ViewManager;
      public var dragDropHelper:DragAndDropHelper;
      public var linkHelper:LinkHelper;
      public var propertieHelper:PropertieHelper;
      public var eventHelper:EventHelper;
      public var keyBoardHelper:KeyBoardHelper;
      public var parent:UIComponent;
      public var selectableComponents:ISelectableComponentsManager;
      public var uraPropertiesForm:IUraPropertiesPanel;
      public var rectangleBuilder:RectangleSelection;
      public var scrollHelper:ScrollHelper;
      public var resourceManager:ResourceManagerImpl;
      public var arrowDragHelper:ArrowDragHelper;
      public var mouseEventHelper:MouseEventHelper;
      public var arrowManager:ArrowManager;
      public var zoomManager:ZoomManager;
      public var sessionHolder:SessionHolder;
      public var dragDropDelegator:IDragAndDropDelegator = new DragDropDelegator();
      
      
      public static function getInstance(parent:UIComponent=null,sessionId:String = null) : UraModelLocator{
      	if ( modelLocator == null){
      		modelLocator = new UraModelLocator(parent,sessionId,new SingletonEnforcer);
      	}
      		
      	return modelLocator;
      }
      
     public function UraModelLocator(parent:UIComponent,sessionId:String,enforcer:SingletonEnforcer){
     	if (enforcer == null) {
          throw new Error( "ModelLocator is a Singleton" );
        }
        this.parent = parent;
        mouseEventHelper = new MouseEventHelper();
        viewManager = new ViewManagerImpl(parent);
        xmlManager = new XmlManagerImpl();
        linkHelper = new LinkHelper(parent,viewManager,mouseEventHelper);
        propertieHelper = new PropertieHelper(parent);
        scrollHelper = new ScrollHelper(parent as Canvas);
        dragDropHelper = new DragAndDropHelper(parent,viewManager,scrollHelper,mouseEventHelper,dragDropDelegator);
        keyBoardHelper = new KeyBoardHelper(parent,viewManager);
        eventHelper = new EventHelper(dragDropHelper,linkHelper,propertieHelper,keyBoardHelper);
        selectableComponents = new SelectableComponentsUtils(viewManager);
        rectangleBuilder = new RectangleSelection(parent,viewManager,mouseEventHelper);
        resourceManager = new ResourceManagerImpl();
        arrowDragHelper = new ArrowDragHelper(parent as Canvas,viewManager,mouseEventHelper);
        arrowManager = new ArrowManagerImpl(parent as Canvas);
        zoomManager = new ZoomManager(viewManager);
        sessionHolder = new SessionHolder(sessionId);
     }
     
    
     
	}
}
class SingletonEnforcer {}
